<%
  user = @user
  user_detail = user.thredded_user_detail
%>
<% content_for :thredded_page_title, t('thredded.nav.moderation') %>
<% content_for :thredded_page_id, 'thredded--moderation-user' %>
<%= render 'nav' %>
<%= thredded_page do %>
  <section class="thredded--main-section">
    <%= view_hooks.moderation_user_page.user_title.render self, user: user do %>
      <h1 class="thredded--moderation--user--title">
        <%= image_tag Thredded.avatar_url.call(user), class: 'thredded--user--avatar' %><%= user.thredded_display_name %>
      </h1>
    <% end %>
    <%= view_hooks.moderation_user_page.user_info.render self, user: user do %>
      <ul class="thredded--moderation--user--info">
        <%= view_hooks.moderation_user_page.user_info_list_items.render self, user: user do %>
          <li><%= t 'thredded.users.user_since_html', time_ago: time_ago(user.created_at) %></li>
          <% if user_detail.last_seen_at %>
            <li><%= t 'thredded.users.last_active_html', time_ago: time_ago(user_detail.last_seen_at) %></li>
          <% end %>
          <% if user_detail.topics_count > 0 %>
            <li><%= t 'thredded.users.started_topics_count', count: user_detail.topics_count %></li>
          <% end %>
          <% if user_detail.posts_count > 0 %>
            <li><%= t 'thredded.users.posts_count', count: user_detail.posts_count %></li>
          <% end %>
          <li><%= render 'user_moderation_state', user: @user %></li>
        <% end  %>
      </ul>
    <% end %>
    <%= view_hooks.moderation_user_page.user_moderation_actions.render self, user: user do %>
      <div class="thredded--user--moderation-actions">
        <% unless user_detail.approved? %>
          <%= button_to t('thredded.moderation.approve_btn'), moderate_user_path,
                        class: 'thredded--button',
                        params: { id: user.to_model.id, moderation_state: 'approved' } %>
        <% end %>
        <% unless user_detail.blocked? %>
          <%= button_to t('thredded.moderation.block_btn'), moderate_user_path,
                        class: 'thredded--button',
                        params: { id: user.to_model.id, moderation_state: 'blocked' } %>
        <% end %>
      </div>
    <% end %>
    <% if @posts.present? %>
      <h2><%= t 'thredded.users.recent_activity' %></h2>
      <%= render_posts @posts,
                       partial: 'thredded/moderation/user_post',
                       content_partial: 'thredded/posts/content' %>
      <%= paginate @posts %>
    <% end %>
  </section>
<% end %>
